#!/usr/bin/env python
# -*- coding:utf-8 -*-

"""
@author zyx
@since 2022/2/13 18:00
@file: c06_多任务协程处理.py
"""

import asyncio
import time


# 特殊的函数
async def get_request(url):
    print('正在请求的网址是:', url)
    # time.sleep(2)
    await asyncio.sleep(2)
    print('请求网址结束！')
    return 123


if __name__ == '__main__':
    start = time.time()
    urls = ['www.1.com', 'www.1.com', 'www.1.com']
    tasks = [asyncio.ensure_future(get_request(url)) for url in urls]
    # 将三个任务对象，添加到一个事件循环对象中
    loop = asyncio.get_event_loop()
    loop.run_until_complete(asyncio.wait(tasks))
    print('总耗时:', time.time() - start)
